package com.dgty.dg_common.base;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import androidx.lifecycle.Lifecycle;
import androidx.viewpager2.adapter.FragmentStateAdapter;

import java.util.List;

/**
 * Title: BaseFragmentPagerAdapter.java
 * Description:基础pagerAdapter
 * Created DateTime: 2023-02-14
 * Created by xxl.
 */

public class BaseFragmentStateAdapter extends FragmentStateAdapter {

    private List<Fragment> mFragment;
    private List<String> mTitleList;

    public void addFragmentList(List<Fragment> fragment) {
        this.mFragment.clear();
        this.mFragment = fragment;
        notifyDataSetChanged();
    }

    public BaseFragmentStateAdapter(@NonNull FragmentActivity fragmentActivity, List<Fragment> fragments) {
        super(fragmentActivity.getSupportFragmentManager(), fragmentActivity.getLifecycle());
        mFragment = fragments;
    }

    public BaseFragmentStateAdapter(@NonNull  FragmentActivity fragmentActivity, List<Fragment> fragments, List<String> mTitle) {
        super(fragmentActivity.getSupportFragmentManager(), fragmentActivity.getLifecycle());
        this.mTitleList = mTitle;
        mFragment = fragments;
    }

    @NonNull
    @Override
    public Fragment createFragment(int position) {
        return mFragment.get(position);
    }

    @Override
    public int getItemCount() {
        return mFragment.size();
    }
}
